#!/bin/sh

# NOTE: edit /etc/hosts to add hfs_q3 item 1st
login=root@hfs_q3
db_name=bora
dir_name=`date "+%Y-%m-%d_%H-%M-%S"`
mkdir -p $dir_name
mongodump -d $db_name -o $dir_name
tar Jcf $dir_name.tar.xz $dir_name
# NOTE: do ssh copy-id 1st
scp $dir_name.tar.xz $login:/tmp
rm -rf $dir_name $dir_name.tar.xz
ssh $login "bash" <<EOF
cd /tmp && tar Jxf $dir_name.tar.xz && mongorestore -d $db_name $dir_name/$db_name && rm -rf $dir_name*
EOF
